//
//  HX_CollectionViewTitle.m
//  UI14-作业（礼物说）
//
//  Created by 韩旭 on 16/8/2.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "HX_CollectionViewTitle.h"
#define kCollectionHead @"headTitle"
@interface HX_CollectionViewTitle ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UILabel *lable;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIButton *btn;
@end

@implementation HX_CollectionViewTitle

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        _lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width / 2, 30)];
        _lable.text = @"栏目";
        _lable.font = [UIFont systemFontOfSize:15];
        _lable.backgroundColor = [UIColor clearColor];
        _lable.textColor = [UIColor lightGrayColor];
        [self addSubview:_lable];
        _btn = [[UIButton alloc] initWithFrame:CGRectMake(_lable.frame.size.width, 0, frame.size.width / 2, _lable.frame.size.height)];
        [_btn setTitle:@"查看更多>" forState:UIControlStateNormal];
        _btn.titleLabel.font = [UIFont systemFontOfSize:15];
        _btn.titleEdgeInsets = UIEdgeInsetsMake(0, 100, 0, 0);
        [_btn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [self addSubview:_btn];
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, _lable.frame.size.height, CGRectGetWidth(frame), CGRectGetHeight(frame) - 30) collectionViewLayout:layout];
        _collectionView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_collectionView];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:kCollectionHead];
        layout.minimumLineSpacing = 10;
        layout.minimumInteritemSpacing = 0;
        layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        CGFloat width = self.frame.size.width * 0.8;
        CGFloat height = (_collectionView.frame.size.height - 40) / 3;
        layout.itemSize = CGSizeMake(width, height);
    }
    return self;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell *cell = [collectionView  dequeueReusableCellWithReuseIdentifier:kCollectionHead forIndexPath:indexPath];
    cell.backgroundColor = COLORAUTO;
    return cell;
}


@end
